<template>
  <!--设备管理-位置设置-->
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="21">
          <a-col :xl="5" :md="11" :sm="24">
            <a-form-item label="项目">
              <a-select :options="levelOneOptions" placeholder="请输入项目" class="input1" v-model="queryParam.projectId"
                style="width: 300px;"></a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :md="11" :sm="24">
            <a-form-item label="设备位置">
              <a-input placeholder="请输入设备位置" class="input1" v-model="queryParam.address"
                style="width: 300px;"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleYujin('add')"  icon="plus" style="background-color:#32cd99;color: white;">新增位置</a-button>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table ref="table" size="middle" v-bind="tableProps" bordered rowKey="id" class="j-table-force-nowrap"
        :scroll="{ x: true }" :columns="columns" :data-source="dataSource" :pagination="ipagination" :loading="loading"
        @change="handleTableChange">
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="status" slot-scope="text, record">
          <a-switch :checked="record.status === '1' ? true:false" @change="updata($event,record)" />
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleYujin('edit',record)" style="margin-right: 20px;">编辑</a>
          <a-popconfirm title="确定删除吗？"  @confirm="handleDelete(record.id,'delete')">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <locations-modal ref="modalForm" @ok="modalFormOk" />
  </a-card>
</template>

<script>
  import {
    JeecgListMixin
  } from '@/mixins/JeecgListMixin'
  import locationsModal from './components/locationsModal'
  import '@/assets/less/TableExpand.less'
  import {
    httpAction,
    getAction,
    postAction
  } from '@/api/manage'
  export default {
    name: 'WtWuziList',
    mixins: [JeecgListMixin],
    components: {
      locationsModal,
    },
    data() {
      return {
        description: '物资明细',
        // 表头
        columns: [{
            title: '位置编号',
            align: 'center',
            width: 200,
            dataIndex: 'number',
          },
          {
            title: '项目',
            align: 'center',
            width: 250,
            dataIndex: 'projectName',
          },
          {
            title: '部门',
            align: 'center',
            width: 200,
            dataIndex: 'departName',
          },
          {
            title: '设备位置',
            align: "center",
            dataIndex: 'address'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 250,
            scopedSlots: {
              customRender: 'action'
            },
          },
        ],
        url: {
          add:'/equipment/wtEquipmentAddress/add',
          edit: '/equipment/wtEquipmentAddress/edit',
          list: '/equipment/wtEquipmentAddress/list',
          detail: '/equipment/wtEquipmentAddress//queryById',
          delete:'/equipment/wtEquipmentAddress/delete',
        },
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30', '50', '100', '200', '300', '400', '500', '600', '700', '1000'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
        dictOptions: {},
        newArr: [],
        levelOneOptions: [],
        treeData1: [],
        dataSource: [],
        newDataSource: [],
        footerDataSource: [],
        pageSwitch: true,
        superFieldList: [],
      }
    },
    created() {
      this.getSuperFieldList()
    },
    mounted() {
      this.newDataSource = this.dataSource
    },
    methods: {
      //获取详情-编辑
      updata(row, record) {
        let params = {
          id: record.id
        }
        getAction(this.url.detail, params).then((res) => {
          if (res.success) {
            let model = res.result;
            let httpurl = this.url.edit;
            if (model.status === '1') {
              model.status = '0';
            } else {
              model.status = '1';
            }
            httpAction(httpurl, model, 'POST').then((res2) => {
              if (res2.success) {
                this.$message.success(res2.message)
                this.loadData(1);
              } else {
                this.$message.warning(res2.message)
              }
            })
          } else {
            this.$message.warning(res.message)
          }
        })
        console.log(22, row, record)
      },
      handleYujin: function(type, record) {
        if (type === 'add') {
          this.$refs.modalForm.title = '新增';
          this.$refs.modalForm.pageType = type;
          this.$refs.modalForm.disabled = false;
          this.$refs.modalForm.add();
        } else if (type === 'edit') {
          this.$refs.modalForm.title = '配置预警';
          this.$refs.modalForm.pageType = type;
          this.$refs.modalForm.disabled = false;
          this.$refs.modalForm.edit(record);
        }
      },
      loadData(arg) {
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1
        }
        var params = this.getQueryParams() //查询条件
        console.log(222, params)
        this.loading = true
        getAction(this.url.list, params)
          .then((res) => {
            if (res.success) {
              //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
              this.dataSource = res.result.records;

              if (res.result.total) {
                this.ipagination.total = res.result.total
              } else {
                this.ipagination.total = 0
              }
              // this.dataHandling(1,this.ipagination.pageSize,this.dataSource)
              //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            } else {
              this.$message.warning(res.message)
            }
          })
          .finally(() => {
            this.loading = false
          })
        getAction(`/sys/sysDepart/getDepartByOrgType?orgType=1`).then((res) => {
          if (res.success) {
            this.treeData1 = []
            let treeList1 = res.result
            for (let a = 0; a < treeList1.length; a++) {
              let temp = treeList1[a]
              temp.isLeaf = temp.leaf
              this.treeData1.push(temp)
            }

            this.levelOneOptions = [...this.treeData1].map((v) => {
              return {
                ...v,
                value: v.id,
                label: v.departName,
              }
            })
          }
        })
      },
      initDictConfig() {},
      getSuperFieldList() {
        let fieldList = []
        fieldList.push({
          type: 'string',
          value: 'name',
          text: '物资名称',
          dictCode: ''
        })
        fieldList.push({
          type: 'string',
          value: 'model',
          text: '型号',
          dictCode: ''
        })
        fieldList.push({
          type: 'string',
          value: 'number',
          text: '数量',
          dictCode: ''
        })
        fieldList.push({
          type: 'string',
          value: 'warehouseName',
          text: '仓库',
          dictCode: ''
        })
        fieldList.push({
          type: 'string',
          value: 'createTime',
          text: '时间',
          dictCode: ''
        })
        fieldList.push({
          type: 'string',
          value: 'type_dictText',
          text: '出库入库选项',
          dictCode: ''
        })

        this.superFieldList = fieldList
      },
    },
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';

  .input1 {
    width: 170px;
    height: 30px;
  }
</style>